import { FLASH_USER, FLASH_EXAM, GETUSERDATA, MESSAGENUM, FLASH_MOB_STATUS } from './mutations-types'
import { loginAccount, getUserData } from '@/service/get-data'
import { setCookie } from '@/untils/storage'
export default{
  // 登录
  async GETUSER ({ commit }, form) {
    let res = await loginAccount(form.username, form.password)
    res = res.data
    if (res.resultCode && res.resultCode === 2000) {
      setCookie('Token', res.data.token) // token值
      setCookie('Exam', res.data.status) // 企业信息认证状态
      setCookie('needUpdateStatus', res.data.infoNeedUpdateStatus) // 完善企业
      setCookie('getTokenTime', Date.parse(new Date())) // token的时间戳
      setCookie('username', res.data.username) // 用户名
      commit(FLASH_USER)
      commit(FLASH_MOB_STATUS, { mobile: res.data.mobile })
      commit(FLASH_EXAM, res.data.status)
      commit(MESSAGENUM, res.data.messageNumber)
    }
    return res
  },
  async getUserData ({ commit }) {
    const res = await getUserData()
    console.log(res)
    // debugger
    commit(GETUSERDATA, res)
  }
}
